<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/21 0021
 * Time: 上午 10:17
 */

namespace app\common\controller;
use think\App;
use think\Controller;
use think\Db;
use think\facade\Hook;
use think\facade\Session;

class Baseadmin extends Controller
{
    public function __construct(App $app = null)
    {
        //钩子判断用户是否登录过了,未登录跳转登录页面
         Hook::listen('CheckAuth');
        parent::__construct($app);
    }
    /**
     * 获取session,判断是否登录
     * @return mixed
     */
    public function islogin(){
        return Session::get('userinfo.id')?true:false;
    }
    /***
     *添加日志
     */
    protected  function adduserlog(){
        $data['messages']='管理员【'.Session::get('userinfo.name').'】'.date('Y-m-d H:i:s',time()).'登录后台系统！';
        $data['userid']=Session::get('userinfo.id');
        $data['addtime']=time();
        $data['status']=1;
        Db::name('adminlog')->insert($data,true);
    }
    public function loginout(){
        Session::destroy();
        $this->redirect('Index/index');
    }
}